﻿namespace GSC.WebControls
{
    using System;
    using System.Collections.Generic;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    public class AsyncIDsDeserialize
    {
        List<string> _ids;
        Control _control;
        public void Deserialize()
        {
            if (_control is LinkButton || _control is ImageButton || _control is Button || _control is DropDownList)
            {
                if (_ids.Contains(_control.ClientID))
                {
                    _ids.Remove(_control.ClientID);
                }
            }
            else
            {
                this.Depth(_control, ref _ids);
            }
        }

        /// <summary>
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="ids"></param>
        private void Depth(Control parent, ref List<string> ids)
        {
            foreach (Control item in parent.Controls)
            {
                if (item is LinkButton || item is ImageButton || item is Button || item is DropDownList)
                {
                    if (ids.Contains(item.ClientID))
                    {
                        ids.Remove(item.ClientID);
                    }
                }
                if (item.HasControls())
                {
                    Depth(item, ref ids);
                }
            }
        }
        /// <summary>
        /// 初始化异步ID序列化。
        /// </summary>
        /// <remarks>初始化异步ID序列化。</remarks>
        /// <param name="control">设置序列化控件。</param>
        /// <param name="ids">设置异步ID列表。</param>
        public AsyncIDsDeserialize(Control control, ref List<string> ids)
        {
            this._control = control;
            this._ids = ids;
        }
    }
}